package com.loan.controller;

import com.loan.dto.Result;
import com.loan.entity.Settings;
import com.loan.repository.SettingsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * Created by huxudong on 17/7/26.
 */
@Controller
@RequestMapping("admin/settings")
public class SettingsController {

    @Autowired
    private SettingsRepository settingsRepository;

    /**
     * 系统设置
     * @return
     */
    @RequestMapping(value = "",method = RequestMethod.GET)
    public String list(Model model) {
        List<Settings> list = settingsRepository.findAll();
        model.addAttribute("list", list);
        return "main";
    }

    /**
     * 修改
     * @return
     */
    @RequestMapping(value = "save",method = RequestMethod.POST)
    @ResponseBody
    public Result save(Long id ,Integer status) {
        Result result = new Result(200,"修改成功");
        Settings settings  = settingsRepository.findOne(id);
        settings.setStatus(status);
        settingsRepository.saveAndFlush(settings);
        return result;
    }

}
